package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.FilterItem;

import java.util.List;

/**
 * Created by wyd on 2017/7/19.
 */

public class FilterAdapter extends BaseAdapter
{
    private List<FilterItem> infoList;
    private Context context;
    public FilterAdapter(List<FilterItem> infoList, Context context) {
        this.infoList = infoList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return infoList.size();
    }

    @Override
    public Object getItem(int position) {
        return infoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder = null;
        if(convertView == null)
        {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.fragment_gridview_item,null);
            holder.textView = (TextView) convertView.findViewById(R.id.fragment_gridview_item_tv);

            convertView.setTag(holder);
        }else
        {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(infoList.get(position).getItemName().toString());

        if (infoList.get(position).isSelect())
        {
            holder.textView.setBackgroundResource(R.drawable.fragment_gridview_item_back2);
            holder.textView.setTextColor(context.getResources().getColor(R.color.light_blue));
        }else {
            holder.textView.setTextColor(context.getResources().getColor(R.color.colorGridViewTextViews));
            holder.textView.setBackgroundResource(R.drawable.fragment_gridview_item_back1);
        }
        return convertView;
    }


    class ViewHolder{
        TextView textView = null;
    }
}
